﻿using SharedFileDownload.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SharedFileDownloadForm
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini");
		private int i = 0;//定义一个i用来使新造的Item名字不同
		TextBox t;//每造一个新Item 然后将Textbox扔进去
		public MainWindow()
		{
			IsLogin();
			InitializeComponent();
			this.DataContext = new ViewModels.MainWindowViewModel();
		}
		private void IsLogin()
		{
			try
			{
				if (File.Exists(path))
				{
					string[] str = null;
					using (StreamReader read = new StreamReader(path))
					{
						str = read.ReadLine().Split('|');
					}
					//判断是否登录
					if (FileShared.connectState(str[0], str[1], str[2]))
					{
						return;
					}
				}
			}
			catch (Exception ex)
			{
				
			}
			this.Hide();
			MessageBox.Show("请登录！");
			new Login().Show();
		}
		private void MenuItem_Click_1(object sender, RoutedEventArgs e)
		{
			//TabItem ti = new TabItem();//造一个新选项卡
			//ti.Header = "新窗口" + (i + 1);//新选项卡的名字
			//TabControl1.Items.Add(ti);//将造好的新选项卡扔进TabControl1里
			//t = new TextBox();//实体化一个新文本框
			//t.Width = 562;
			//t.Height = 305;
			////下面开始将文本框添加到新造的选项卡中
			//ti.Content = t;
			////每造一个新窗口便默认突出显示为新窗口
			//TabControl1.SelectedIndex = i + 1;
			////TabControl1.SelectedIndex = TabControl1.Items.Count - 1;
			//i++;
			////双击每个选项卡触发的事件
			//ti.MouseDoubleClick += ti_MouseDoubleClick;
		}
		private void ti_MouseDoubleClick(object sender, MouseButtonEventArgs e)
		{
			TabItem s = (TabItem)sender; //sender代表每个选项卡
			//TabControl1.Items.Remove(s);
		}
		private void MenuItem_Click_4(object sender, RoutedEventArgs e)
		{
			this.Close();
			Application.Current.Shutdown();
		}
		private void GetFiles()
		{

		}
	}
}
